/**
 * Copyright (C) 2007-2011 JUG Events Team <info@jugevents.org>
 *
 * This file is part of JUG Events Web Application.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package it.jugpadova.blo;

import org.directwebremoting.ScriptSession;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.proxy.dwr.Util;

import it.jugpadova.util.TextFilterUtils;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Component;

/**
 *
 * @author lucio
 */
@Component
@RemoteProxy(name="filterBo")
public class FilterBo {

    public FilterBo() {
    }

    @RemoteMethod
    public void populatePreview(String text, String filter,
            String previewDivId) {
        String result =
                FilterBo.filterText(text, filter, false);
        WebContext wctx = WebContextFactory.get();
        ScriptSession session = wctx.getScriptSession();
        Util util = new Util(session);
        util.setValue(previewDivId, result, false);
    }

    public static String filterText(String text, String filter,
            boolean escapeXml) {
        // Only Textile for now
        String result = TextFilterUtils.formatText(text, TextFilterUtils.TEXTILE_FILTER);
        return result;
    }
}
